package org.pombo.sqm;

import org.pombo.gtm.Action;
import org.pombo.gtm.ChanceNode;

class ChanceNodeWorstPayoffCalculator implements NodeWorstPayoffCalculator<ChanceNode> {

	private ChanceNode node;
	private WorstPayoffCalculatorFactory calculate;

	ChanceNodeWorstPayoffCalculator(WorstPayoffCalculatorFactory worstPayoffCalcFactory) {
		this.calculate = worstPayoffCalcFactory;
	}

	public void setNode(ChanceNode node) {
		this.node = node;
	}

	public double worstPayoff() {
		double worstPayoff = 0;
		for (Action action : this.node.getActions()) {
			worstPayoff += this.node.getProbabilityForAction(action)
						* this.calculate.on(this.node.getNodeForAction(action)).worstPayoff();
		}
		return worstPayoff;
	}

}
